<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>router中嵌套路由中的使用</title>
</head>
<body>
<div id="app">
    <router-link to="/product" tag="button">商品管理</router-link>
    <router-view></router-view>
</div>
<!--模板-->
<template id="proc">
    <div>
        <h1>商品管理</h1>
        <router-link to="/product/add" tag="button">商品添加</router-link>
        <router-link to="/product/edit" tag="button">商品编辑</router-link>
        <router-view></router-view>
    </div>
</template>
<template id="add">
        <h4>商品添加</h4>
</template>
<template id="edit">
        <h4>商品编辑</h4>
</template>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@3.4.9/dist/vue-router.js"></script>

<script>
    //声明组件模板
    const product = {
        template:'#proc',
    };
    const add = {
        template: '#add',
    };
    const edit = {
        template: '#edit',
    };

    //定义路由对象
    const router = new VueRouter({
        routes:[
            {
                path: '/',
                redirect:'product',
            },
            {
                path:'/product',
                component:product,
                children:[
                    {path:'add',component:add},
                    {path:'edit',component:edit},
                ]
            },


        ]
    });

    const app = new Vue({
        el: "#app",
        data: {},
        methods: {},
        //定义路由对象
        router,
    });
</script>
</html>
